<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta charset="UTF-8">
		<title>稳盈宝_共富网_Gofull.com.cn</title>
		<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>	
		<script type="text/javascript" src="/v3/js/event/global-1.1.0.min.js"></script>	
		<script src="/v3/js/wybScroll.js" type="text/javascript"></script>		
		<script src="/v3/js/startMove.js" type="text/javascript"></script>	
		<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
		<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
		<script type="text/javascript" src="/v3/js/showts.js"></script>
	</head>
	<body>
		<div id="wrap">
			<ul class="proItem">
				<s:if test="#request.yebMap.productStatus == 1">
				<li onclick="location.href='/loanYebDetailInvest.do?pid=${yebMap.pid }'">
					余额宝
					<span class="proRate">${yebAnnualRate}%</span>
				</li>
				</s:if>
				<s:else>
				<li class="disable">
					余额宝
					<span class="proRate">已售完</span>
				</li>
				</s:else>
				<s:if test="#request.ylbMap.productStatus == 1">
				<li onclick="location.href='/loanYlbDetailInvest.do?pid=${ylbMap.pid }'">
					月利宝
					<span class="proRate">${ylbMap.productAnnualRate }%</span>
				</li>
				</s:if>
				<s:else>
				<li class="disable">
					月利宝
					<span class="proRate">已售完</span>
				</li>
				</s:else>
				<s:if test="#request.jfbMap.productStatus == 1">
				<li onclick="location.href='/loanJfbDetailInvest.do?pid=${jfbMap.pid }'">
					季发宝
					<span class="proRate">${jfbMap.productAnnualRate }%</span>
				</li>
				</s:if>
				<s:else>
				<li class="disable">
					季发宝
					<span class="proRate">已售完</span>
				</li>
				</s:else>
				<s:if test="#request.debtMap.debtStatus != 2">
				<li class="disable">
					债权
					<span class="proRate">已售完</span>
				</li>
				</s:if>
				<s:else>
				<li onclick="location.href='/loanDebtDetailInvest.do'">
					债权
					<span class="proRate">${debtMap.realAnnualRate }%</span>
				</li>
				</s:else>
			</ul>
			<div class="itemInfo">
				<p class="itemTo">年化收益率</p>
				<img src="/v3/images/circle_bg2.png"/>
				<ul id="text_list">	
				<s:if test="#request.wyblist.size>0">
					<s:iterator value="#request.wyblist" var="wyb" status="st" >
					<li>
						<div <s:if test="#st.index==0"> class="infoShow" </s:if> >
							<p class="itemRate" id="q_hieght">${wyb.annualRate }%</p>
							<p class="itemIf"><a href="/wchatWybDetail.do?id=${wyb.id }">查看详情>></a></p>
						</div>
					</li>
					</s:iterator>
				</s:if>
				</ul>
			</div>
			<s:if test="#request.wyblist.size>0">
				<s:iterator value="#request.wyblist" var="wyb" status="st" >
					<div name="investSum"  <s:if test="#st.index!=0"> style="display:none " </s:if> class="reMoney">可售金额：￥${wyb.investSum}</div>
					<s:if test="#st.index==0"> <input type="hidden" id="winvestSum" value="${wyb.investSum}"> </s:if>
				</s:iterator>
			</s:if>
			<s:if test="#request.availableVoucherList.size>0">
						<div class="useVoucher">
							<div class="yCheckbox">
							<span class="ico" id="novice-chk"></span>
							</div>
							<select id="voucherSelect">
							<s:iterator value="#request.availableVoucherList" var="availableVoucher" status="s">
							<option value="${availableVoucher.id }" id="voucher${availableVoucher.id }">
								投资抵用券 ￥${availableVoucher.remainMoney }</option>
							</s:iterator>
							</select>
							<s:iterator value="#request.availableVoucherList" var="availableVoucher" status="s">
							<span id="availableVoucherAmount" class="availableVoucherAmount"
								voucherid="${availableVoucher.id}" leftamount="${availableVoucher.remainMoney }" 
								voucherType="${availableVoucher.voucherType}" discountratio="${availableVoucher.exchangeRate}" 
								typetitle="投资抵用券"></span>
						</s:iterator>
						</div>
			</s:if>
			<div class="limit_box" id="limit_box">
			<div id="ico_list">
				<a href="javascript:void(0)" id="btn_prev" class="btn_scroll"><i id="icon-prev" class="icon-prev"></i></a>
				<a href="javascript:void(0)" id="btn_next" class="btn_scroll showBtn"><i id="icon-next" class="icon-next"></i></a>
				<div class="limit_con">
				<ul name="uls" style="left: 0px;"> 
				<s:if test="#request.wyblist.size>0">
					<s:iterator value="#request.wyblist" var="wyb" status="st" >
					<li <s:if test="#st.index==0"> class="active" </s:if> ><a href="javascript:void(0)" data="${wyb.id}" investSum="${wyb.investSum}" ><i <s:if test="#wyb.isDayThe==2"> class="icon-Day" </s:if> <s:else> class="icon-${wyb.deadline}M"</s:else> ></i><s:if test="#wyb.isDayThe==2"> ${wyb.deadline}天 </s:if> <s:else> ${wyb.deadline}个月 </s:else></a></li>
					</s:iterator>
				</s:if>
				</ul>
				</div>
			</div>	
			</div>
			<div class="money-input">
				<div class="login_input inv_input">
				<div class="r_line">
				<i class="icon-inMoney"></i>
				</div>
				<input type="hidden" id="realnameFlag" value="${session.user.isBindIdNo}">
				<div class="in_put"><input onkeyup="calAvailableVoucherAmount();" placeholder="购买金额/最低50元" id="inputAmount" name="inputAmount" maxlength="17" type="tel"></div>
				</div>
				<div class="box-bottom"><img src="/v3/images/box_icon.jpg"/></div>
			</div>
			<div class="Nxt-btn"><a id="investBt" href="javascript:invest();">确认购买</a>
			<a href="/wchatRealNameAuthen.do" class="btn" id="realNameBt" style="display: none;">立即实名认证</a></div>
			<p class="inv-note">每个工作日&nbsp;10:00、14:00、17:00&nbsp;更新总额度</p>
		</div>
		<jsp:include page="/include/v3/footer.jsp"></jsp:include>
	</body>
	<script type="text/javascript">	
	$(".limit_con ul li a").click(function(){
		$("#winvestSum").val($(this).attr("investsum"));
	});
	var product = {
			remain : '$("#winvestSum").val()',
			id : $(".active a").attr("data"),
			usableSum : ${accmountStatisMap.usableSum},
		};
	var usableSum = '${accmountStatisMap.usableSum}';
	$(function(){
	Util.CustomCheckbox($('.yCheckbox'));
	  $('#agreeContract').click(function(){
	    if ($('#agreeContract').attr("checked") == "checked") {
	      $('#agreeContract').removeAttr("checked");
	    } else {
	      $('#agreeContract').attr("checked", "checked");
	    }
	  });
	  $('#novice-chk').click(function(){
		    if ($('#novice-chk').attr("checked") == "checked") {
		      $('#novice-chk').removeAttr("checked");
		    } else {
		      $('#novice-chk').attr("checked", "checked");
		    }
	 }); 
	});
	/**
	//刷新验证码
	function coderefresh() {
	    var verifyCode = $("#verifyCodeImg");
	    var now = new Date();
	    verifyCode.attr("src",'I4008lOve893gOfUll983/imageCode.do?pageId=wybWchatInvest&d=' + now.getTime());
	}
	**/
	//投资检查
	function investCheck() {
		var errorTip = $('#errorTip');
		var cash = Number(usableSum);
	    var investAmountInput = $("#inputAmount");
	    var investAmount = investAmountInput.val();
	    var maxInvestAmount = Number($("#winvestSum").val());
	    var investableCash = Number(usableSum);
	    var availableCouponAmount = Number($("#availableCouponAmount").html());
		 var reg = /^\d+$/;
	    if(maxInvestAmount == 0){
	    	showAlert('当前稳盈宝已满');
	        return false;
	    }
	    if(reg.test(investAmount)){
	        var couponReg = /^\d+(\.\d+)?$/;
	        if ((cash - investAmount) < 0) {
	        	showAlert('您的余额(￥' + cash + ')不足');
	        	$("#sure-bt").html("<a href='/quickpayment.do'>立即充值</a>");
				return false;
			}
	        if((investAmount-maxInvestAmount)>0){
	        	showAlert('当前最大可投'+maxInvestAmount+'元');
	            return false;
	        }
	        if(investAmount<50){
	        	showAlert('每笔最少需投50元');
	            return false;
	        }
	        if(((maxInvestAmount-investAmount)<50)&&(maxInvestAmount-investAmount)!=0){
	            var requiredLeftAmount = Number(maxInvestAmount-50);
	            if(requiredLeftAmount > 50){
	            	showAlert('可投金额为'+maxInvestAmount+'或50~'+requiredLeftAmount);
	            }else if(requiredLeftAmount <= 50){
	            	showAlert('可投金额为'+maxInvestAmount);
	            }
	            return false;
	        }
	        /**
	        var verifyCodeInput = $("#authCode");
	        var verifyCode = verifyCodeInput.val();
	        if(verifyCode == ''){
	        	errorTip.html('请输入验证码');
	            return false;
	        }
			
	        if($('#agreeContract').attr("checked") != "checked"){
	        	errorTip.html('请同意共富网投资管理协议');
	            return false;
	        }**/
	        
	        //未实名认证，不能投资
	    	if($("#realnameFlag").val() == "0"){
	    		showAlert('未实名认证，不能投资');
	    		$('#realNameBt').show();
				$('#investBt').hide();
	            return false;
	        }
	        return true;
	    }else{
	    	showAlert('请输入50~'+maxInvestAmount+'的整数');
	        return false;
	    }
	}
	function invest() {
	  if(!investCheck()){
	    return;
	  };
	  
	  var voucherId = 0;
	  if($('#novice-chk').attr("checked") == "checked"){
		voucherId = $("#voucherSelect").val();
	  }
	  
	  var errorTip = $('#errorTip');
	  var investAmount = $("#inputAmount").val();
	  var verifyCode = $("#authCode").val();
	  
	  var param = {};
	  param['paramMap.id'] = product.id;
	  param["paramMap.pageId"] = "wybWchatInvest";
	  param["paramMap.code"] = verifyCode;
	  param['paramMap.amount'] = investAmount;
	  param['paramMap.voucherId'] = voucherId; 
	  
	  $.ajax({
	          dataType: 'json',
	          url: "/financeInvest.do",
	          data: param,
	          type: 'POST',
	          beforeSend: function() {
	              $("#investBt").attr("href","javascript:;").html("正在加入...").addClass("gbtn-disabled");
	          },
	          success: function(data) {
	              if(data.msg == 1){
	            	  $("#inputAmount").val("");
	            	  window.location.href="/investSuccess.do";
	             // window.location.href="/wchatWybDetail.do?id="+product.id;
	              }else{
	                  if(data.msg == '验证码错误'){
	                      coderefresh();
	                      showAlert("验证码错误");
	                      $("#investBt").attr("href","javascript:invest();").html("我要购买").removeClass("gbtn-disabled");
	                  }else{
	                	  coderefresh();
	                	  showAlert(data.msg);
	                      $("#investBt").attr("href","javascript:invest();").html("我要购买").removeClass("gbtn-disabled");
	                  }
	              }
	          },
	          error: function() {
	        	  coderefresh();
	        	  showAlert("投资失败，请刷新页面或稍后再试");
	          }
	      });

	}
	//计算可使用红包金额
	function calAvailableVoucherAmount(){
	    var inputAmount = Number($("#inputAmount").val());
	    var availableVoucherAmount = $(".availableVoucherAmount");
	    for(var i=0,len=availableVoucherAmount.length;i<len;i++){
	        var leftAmount = Number($(availableVoucherAmount[i]).attr("leftamount"));
	        var voucherType = Number($(availableVoucherAmount[i]).attr("voucherType"));
	        var discountRatio = Number($(availableVoucherAmount[i]).attr("discountratio"));
	        var discountAmount = Number($(availableVoucherAmount[i]).attr("discountamount"));
	        var voucherId = $(availableVoucherAmount[i]).attr("voucherid");
	        var typeTitle = $(availableVoucherAmount[i]).attr("typetitle");
	        var useVoucher=$('#voucher' + voucherId);
	        if(voucherType == 1){
	            var availableAmount = inputAmount*discountRatio;
	            if(availableAmount > leftAmount){
	              availableAmount = leftAmount;
	            }
	        }
	       
	        if(isNaN(availableAmount)){
	            availableAmount = 0;
	        }
	        useVoucher.html(typeTitle + "￥" + availableAmount.toFixed(2));
	        useVoucher.attr("useVoucherAmount", availableAmount.toFixed(2));
	    }
	}
	
	</script>
</html>
